<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>用户列表</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../static/css/font.css">
		<link rel="stylesheet" href="../../../static/css/weadmin.css">
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
	      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
		<![endif]-->
		<style>
			.layui-table-cell {
			height: 35px;
			/* line-height:35px; */
			}
		</style>
	</head>

	<body>
		<div class="weadmin-nav">
			<span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">管理员管理</a>
        <a>
          <cite>管理员列表</cite></a>
      </span>
			<a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
				<i class="layui-icon" style="line-height:30px">ဂ</i></a>
		</div>
		<div class="weadmin-body">
			<div class="weadmin-block">
				<!-- <button class="layui-btn layui-btn-danger" onclick="delAll(this,'{{d.id}}')"><i class="layui-icon"></i>批量删除</button> -->
				<button class="layui-btn" onclick="WeAdminShow('添加用户','/admin/user/add',700)"><i class="layui-icon"></i>添加管理员</button>
				<span class="layui-laypage-count" style="line-height:40px"></span>
			</div>
			<table id="demo" lay-filter="test" class="layui-hide"></table>

<script src="../../../lib/layui/layui.js"></script>
		</div>
		<script src="../../../lib/layui/layui.js" charset="utf-8"></script>
		<script src="../../../static/js/eleDel.js" type="text/javascript" charset="utf-8"></script>
		<script>
			layui.use('table', function(){
			  var table = layui.table;
			  //第一个实例
			  table.render({
				elem: '#demo'
				,height: 350
				,url: '/admin/user/list/api' //数据接口
				,page: true //开启分页
				// ,toolbar: '#toolbarDemo'
				,limit:5
				,cols: [[ //表头
				  {type: 'checkbox', fixed: 'left'}
				  ,{field: 'id', title: 'ID',fixed: 'left'}
				  ,{field: 'username', title: '用户名'}
				  ,{field: 'email', title: '邮箱'}
				  ,{field: 'phone', title: '手机'}
				  ,{field: 'roleid', title: '角色',templet: '#role'}
				//   ,{field: 'brief', title: '角色属性'}
				  ,{field: 'state', title: '状态',templet: '#state'}
				  ,{field: 'wealth', title: '操作',toolbar: '#caozuo'}
				]]
			  });
			});
			</script>
			<script type="text/html" id="caozuo">
				<a class="layui-btn layui-btn-danger layui-btn-xs layui-bg-orange" lay-event="edit" onclick="WeAdminShow('设置','/admin/user/setup?id={{d.id}}',600,300)">设置</a>
				<a class="layui-btn layui-btn-xs" lay-event="edit" onclick="WeAdminShow('编辑','/admin/user/edit?id={{d.id}}',700,450)">编辑</a>
				<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" onclick="user_del(this,'{{d.id}}')">删除</a>
			</script>
			<script type="text/html" id="role">
				{{#  if(d.roleid == 1){ }}
				<button type="button" class="layui-btn layui-btn-sm layui-bg-red layui-btn-radius">{{d.rolename}}</button>
				{{#  } else if(d.roleid == 2){ }}
				<button type="button" class="layui-btn layui-btn-sm layui-bg-orange layui-btn-radius">{{d.rolename}}</button>
				{{#  } else if(d.roleid == 3){ }}
				<button type="button" class="layui-btn layui-btn-sm layui-bg-black layui-btn-radius">{{d.rolename}}</button>
				{{#  } else { }}
				<button type="button" class="layui-btn layui-btn-sm layui-bg-blue layui-btn-radius">{{d.rolename}}</button>
				{{#  } }}
			  </script>
			  <script type="text/html" id="state">
				<!-- {{#  if(d.state == 1){ }}
				<span class="layui-btn layui-btn-normal layui-btn-xs">已启用</span>
				{{#  } else { }}
				<span class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled">已停用</span>
				{{#  } }} -->
				<input type="checkbox" id="state" name="state" value="{{d.id}}" lay-skin="switch" lay-text="已启用|已禁用" lay-filter="state" {{ d.state == 1 ? 'checked' : '' }} >
			  </script>
			  <script>
				  layui.use(['table','jquery','layer','form'], function(){
					  var table = layui.table;
					  var layer = layui.layer
					  var $ = layui.jquery
					  var form = layui.form;


					  window.user_del = function (obj,id) {
					  layer.confirm("确认删除吗？",function(index){
						  //发一部数据
						  $.get('/admin/user/del?userid=' + id).then((res)=>{
							layer.msg("已删除！",{
							  icon:1,
							  time:2000
							})
							setTimeout(()=>{
								location.reload()
							})
						  })
					  });
				  }

				  //状态开关
				  form.on('switch(state)', function(obj){
						var id = this.value; // 当行ID
						var state = this.checked ? '1' : '0'; // 选中状态
						var llo = layer.load(); //layer.load() - 加载层
							$.ajax({
							url: '/admin/user/list/state',
							cache: false,
							type: "post",
							dataType: "json",
							data: {id: id,state: state},
							 // 参数
							success: function(data) {
										layer.close(llo); //layer.close(index) - 关闭特定层
										msgcode(data, function() {
												layer.close(llo)
												layer.msg(data.data);
												window.parent.tableList.reload({
											where :{},// 设定异步数据接口的额外参数，任意设
										}, 'data'); //只重载数据
											});
										},
							error: function(xhr) {
										layer.close(llo); //关闭特定层
											layer.msg('系统错误，请联系管理员');
										}
								});
						layer.close(llo);
					});
				  })
			  </script>
	</body>

</html>